/**
 * 
 */
package com.wsd.action.admin;

import java.util.Date;
import java.util.List;

import org.apache.struts2.json.annotations.JSON;

import com.wsd.action.BaseAction;
import com.wsd.bean.Link;
import com.wsd.service.LinkService;

/**
 * @author Administrator
 *
 */
public class LinkAction extends BaseAction{
	private LinkService linkService;
	private int limit;
	private int start;
	private int total;
	private Link link;
	private int[] ids;
	@JSON(serialize = false)
	public Link getLink() {
		return link;
	}

	public void setLink(Link link) {
		this.link = link;
	}

	@JSON(serialize = false)
	public int getTotal() {
		return total;
	}

	public void setTotal(int total) {
		this.total = total;
	}
	@JSON(serialize = false)
	public int getLimit() {
		return limit;
	}

	public void setLimit(int limit) {
		this.limit = limit;
	}
	@JSON(serialize = false)
	public int getStart() {
		return start;
	}

	public void setStart(int start) {
		this.start = start;
	}

	@JSON(serialize = false)
	public LinkService getLinkService() {
		return linkService;
	}

	public void setLinkService(LinkService linkService) {
		this.linkService = linkService;
	}
	@JSON(serialize = false)
	public int[] getIds() {
		return ids;
	}

	public void setIds(int[] ids) {
		this.ids = ids;
	}

	public String allLinks(){
		List<Link> links = linkService.findAll(start, limit);
		total = linkService.findAllCount();
		result.put("links", links);
		result.put("total", total);
		return AJAX;
	}
	
	public String save(){
		link.setAddDate(new Date());
		linkService.save(link);
		success = true;
		return AJAX;
	}
	
	public String update(){
		link.setAddDate(new Date());
		linkService.update(link);
		success = true;
		return AJAX;
	}
	
	public String delete(){
		for(int id : ids ){
			linkService.deleteById(id);
		}
		success = true;
		return AJAX;
		
	}
	
	
	

}
